package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.MyPackageCardProjectModel;
import com.czy.owner.utils.TimeUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/4/19 0019.
 */

public class MyPackageCardProjectAdapter extends RecyclerArrayAdapter<MyPackageCardProjectModel> {
    private Context ctx;

    public MyPackageCardProjectAdapter(Context context) {
        super(context);
        this.ctx = context;

    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyPackageCardProjectViewHolder(parent, ctx);
    }

    class MyPackageCardProjectViewHolder extends BaseViewHolder<MyPackageCardProjectModel> {
        private TextView tv_package_card_name;
        private TextView tv_use_time;
        private TextView tv_old_price;
        private TextView tv_new_price;
        private TextView tv_use_store;
        private Context ctx;


        public MyPackageCardProjectViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_package_card_project);
            tv_package_card_name = $(R.id.tv_package_card_name);
            tv_use_time = $(R.id.tv_use_time);
            tv_old_price = $(R.id.tv_old_price);
            tv_new_price = $(R.id.tv_new_price);
            tv_use_store = $(R.id.tv_use_store);
            this.ctx = ctx;
        }

        @Override
        public void setData(final MyPackageCardProjectModel model) {

            long startTime = model.getStartTime();
            long endTime = model.getEndTime();

            if (startTime == 0 || endTime == 0) {
                tv_use_time.setText("永久有效");
            } else {
                tv_use_time.setText(TimeUtils.formatTimeDifference4(startTime) + "-" + TimeUtils.formatTimeDifference4(endTime) + "有效");
            }
            tv_use_store.setText("限"+model.getStoreName()+"使用");
            tv_package_card_name.setText(model.getPackageName());
            tv_old_price.setText("原价￥" + String.format("%.2f", model.getOriginalPrice()));
            tv_new_price.setText(String.format("%.2f", model.getPrice()));
            tv_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰

        }
    }
}
